// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
// 引入element UI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

/* 引入Vant */
import Vant from 'vant';
import 'vant/lib/index.css'
Vue.use(Vant);

// 引入路由
import router from './router';

// 引入状态管理
import store from './vuex/store';
Vue.prototype.$store = store;

// 引入icon
import './assets/icon/iconfont.css';
import './assets/icon/iconfont.js';

// 挂载 uitls
import Utils from './utils/index';
Vue.prototype.$utils = Utils;

// 注册全局过滤器/时间戳转换日期
import globalFilter from '@/utils/filter';
Object.keys(globalFilter).forEach((key) => {
  Vue.filter(key, globalFilter[key])
});

// 引入axios请求
import axios from 'axios';
Vue.prototype.$axios = axios;

// 使用element UI
Vue.use(ElementUI);

// 过滤器
import * as custom from './utils/util';
Object.keys(custom).forEach(key => {
    Vue.filter(key, custom[key])
});

import global from './global';  //引用
Vue.use(global);  //将全局函数当做插件来进行注册

Vue.config.productionTip = false;

// element select 下拉框加载更多
Vue.directive('selectLoadMore', {
    bind (el, binding) {
        // 获取element-ui定义好的scroll盒子
        const selectDom = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
        selectDom .addEventListener('scroll', function () {
            if (this.scrollHeight - this.scrollTop < this.clientHeight + 1) {
                binding.value();
            }
        })
    }
});

new Vue({
    el: '#app',
    router,
    store, //使用store vuex状态管理
    components: { App },
    template: '<App/>',
    data: {
        // 空的实例放到根组件下，所有的子组件都能调用
        Bus: new Vue()
    }
})